﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewList.aspx.cs" Inherits="Web.ViewList" MasterPageFile="~/Main.Master" ValidateRequest="false" Title="Views" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

<script>
function filterAdd() {

    var sqlColumn = $('#sqlColumn').val();
    if (sqlColumn == "")
        return;

    var filter = $('#filters option:selected').val() + "(" + sqlColumn + ")";

    $('#content_listFilters').append("<div class='filterItem' data-value='" + filter + "'>" + $('#filters option:selected').val() + " " + sqlColumn + " <a href='#' onclick='filterDelete(this);'>X</a></div>");

    $('#content_hidFilters').val($('#content_hidFilters').val() + " " + filter);
}

function filterDelete(elem) {

    $elem = $(elem).parent();

    var filters = $('#content_hidFilters').val();
    $('#content_hidFilters').val(filters.replace($elem.attr('data-value'), ''));

    $elem.remove();
}

function clearForm() {

    $('#content_hidID').val('');
    $('#content_btnUpdate').val('New');
    $('input[type=text]').val('');
    $('textarea').val('');
    $('#content_hidFilters').val();
    $('#content_listFilters').empty();
}

$(document).ready(function () {

    if ($('#content_hidID').val() == '') {
        $('#btnClear').hide();
    }
});

</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="content" runat="server">

    <h3>Views</h3>
    <asp:Literal ID="litList" runat="server" />

    <h5>New</h5>
    <asp:HiddenField ID="hidID" runat="server" />
    
    <table cellpadding="0" cellspacing="0" class="formfill">
    <tr>
        <td>Name</td><td><asp:TextBox ID="txtName" runat="server" /> Display in menu <asp:CheckBox ID="chkInMenu" runat ="server" /></td>
    </tr>
    <tr>
        <td>Result viewer</td><td><asp:DropDownList ID="drpViews" runat="server" /></td>
    </tr>
    <tr>
        <td colspan="2">
        SQL<br />
        <asp:TextBox ID="txtSQL" TextMode="MultiLine" Rows="10" Columns="100" runat="server" />
    </td></tr>
    <tr>
        <td colspan="2">
        Filters<br /><asp:HiddenField ID="hidFilters" runat="server" />
        <div id="listFilters" runat="server"></div>
        
        &nbsp;Where item: &nbsp;<input type="text" id="sqlColumn" /> &nbsp;&nbsp;Filter Type: <asp:Literal ID="litFilterSelection" runat="server" />&nbsp;<input type="button" value="add" onclick="filterAdd()" />

    </td></tr>
    <tr><td colspan="2" align="right">
    
        <input type="button" id="btnClear" onclick="clearForm()" value="Clear" />
        <asp:Button ID="btnUpdate" runat="server" OnClick="btnUpdate_Click" Text="New" />
    </td></tr>
    
    </table>


        
</asp:Content>